// Fill out your copyright notice in the Description page of Project Settings.


#include "MeteorUnit.h"
#include "GameFramework/Character.h"
#include "Components/SkeletalMeshComponent.h"
#include "MeteorAnimationComponent.h"
#include "Components/CapsuleComponent.h"
// Sets default values
AMeteorUnit::AMeteorUnit(const FObjectInitializer& ObjectInitializer)
	: Super(ObjectInitializer)
{
 	// Set this character to call Tick() every frame.  You can turn this off to improve performance if you don't need it.
	PrimaryActorTick.bCanEverTick = true;
	GetMesh()->SetSkeletalMesh(NULL);
	MeshComponent = ObjectInitializer.CreateDefaultSubobject<UMeteorAnimationComponent>(this, TEXT("MeshComponent"));

	USkeletalMesh * pNewMesh = LoadObject<USkeletalMesh>(NULL, TEXT("SkeletalMesh'/Game/Characters/Mesh/P0/P0_all.P0_all'"));
	MeshComponent->SetSkeletalMesh(pNewMesh);
	MeshComponent->SetMobility(EComponentMobility::Movable);
	RootComponent = MeshComponent;
	GetCapsuleComponent()->InitCapsuleSize(42.f, 96.0f);
	UCapsuleComponent* capsule = this->GetCapsuleComponent();

	capsule->AttachToComponent(RootComponent, FAttachmentTransformRules::KeepRelativeTransform);
	MeshComponent->ChangeAction(0);
}

// Called when the game starts or when spawned
void AMeteorUnit::BeginPlay()
{
	Super::BeginPlay();
	
}

// Called every frame
void AMeteorUnit::Tick(float DeltaTime)
{
	Super::Tick(DeltaTime);
	if (MeshComponent != nullptr) {
		MeshComponent->UpdateAnimation(DeltaTime);
	}
}

// Called to bind functionality to input
void AMeteorUnit::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent)
{
	Super::SetupPlayerInputComponent(PlayerInputComponent);

}

